<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2023/5/15
 * Time: 9:26
 */

namespace App\Library\PrintingOptions;


use App\Rep\OrderSecondRep;

class PrintingOptions
{


    /**
     * 接单单据
     * title                         标题
     * qr_code                       二维码
     * order_number                  订单号
     * customer_name                 客户名称
     * order_date                    订单时间
     * delivery_date                 交货时间
     * serial_number                 流水号
     * emergency_procedure           紧急程度
     * model_number                  型号
     * specification_id              规格
     * color                         颜色
     * direction                     方向
     * remark                        备注
     * draw_time                     领单时间
     * employee_user                 领单人
     * employee_user_id              领单人ID
     * job_type                      工种
     */
    public function getOrderInvoices($list,$order_child,$count,$order_child_id_arr){
        $array = [];
        $res = [
            'title'=>'接单单据',
            'qr_code'=>json_encode(["order_id"=>$order_child['order_id']??'',"order_child_id"=>$order_child_id_arr??'']),
            'order_number'=>$order_child['order']['order_number']??'',
            'customer_name'=>$order_child['order']['customer']['customer_name']??'',
            'order_date'=>$order_child['order']['order_date']??'',
            'delivery_date'=>$order_child['order']['delivery_date']??'',
            'serial_number'=>$order_child['order']['serial_number']??'',
            'emergency_procedure'=>$order_child['order']['emergency_procedure']??"",
            'product_name'=>$order_child['order']['product']['product_name']??"",
            //'second_name'=>$order_child['order_second']['product']['product_name']??"",
            'model_number'=>$order_child['order']['model_number']['model_number']??'',
            'specification_id'=>$order_child['order']['specification']['specification']??'',
            'color'=>$order_child['order']['color']['color']??'',
            'direction'=>$order_child['order']['direction']??'',
            'remark'=>$order_child['order']['remark']??'',
            'draw_time'=>$order_child['draw_time']??"",
            'employee_user'=>$order_child['employee']['employee_name']??'',
            'employee_user_id'=>$order_child['employee_user_id']??'',
            'job_type'=>$order_child['job_type']['job_type']??'',
            'count'=>$count
        ];
        foreach($list as $k=>$v){
            $array[$k]['size'] = $v->size;
            $array[$k]['field_name'] = $v->field_name;
            $array[$k]['field'] = $v->field;
            $array[$k]['value'] = $res[$v->field];
            if($v->field == 'second_name'){
                $array[$k]['size'] = $v->size;
                $array[$k]['field_name'] = (new OrderSecondRep())->getModelnameByOrderSecondId($order_child['order_second_id'])??'';
                $array[$k]['field'] = $v->field;
                $array[$k]['value'] = $res[$v->field];
            }
        }
        return $array;
    }

    /**
     * 外包单据
     */
    public function getEpibolyOrderInvoices($list,$order_child_list){
        $array = [];
        foreach($order_child_list as $k=>$v){
            $res = [];
            $res = [
                'title'=>'外包单据',
                'qr_code'=>json_encode(["order_id"=>$v['order_id'],"order_child_id"=>$v['id']]),
                'order_number'=>$v['order']['order_number'],
                'customer_name'=>$v['order']['customer']['customer_name'],
                'order_date'=>$v['order']['order_date'],
                'delivery_date'=>$v['order']['delivery_date'],
                'serial_number'=>$v['order']['serial_number'],
                'emergency_procedure'=>$v['order']['emergency_procedure'],
                'product_name'=>$v['order']['product']['product_name'],
                'model_number'=>'【'.$v['order']['product']['product_name'].'】'.$v['order']['model_number']['model_number']??'',
                'specification_id'=>$v['order']['specification']['specification'],
                'color'=>$v['order']['color']['color'],
                'direction'=>$v['order']['direction'],
                'remark'=>$v['order']['remark'],
                'draw_time'=>$v['draw_time'],
                'employee_user'=>$v['employee']['company_name']??'',
                'employee_user_id'=>$v['employee_user_id'],
                'job_type'=>$v['job_type']['job_type'],
                'epiboly_time'=>$v['epiboly_time']
            ];
            $arrs = [];
            foreach($list as $kk=>$vv){
                $arr = [];
                if($vv->field == 'draw_time'){
                    $arr['field'] = 'epiboly_time';
                    $arr['size'] = $vv->size;
                    $arr['field_name'] = '外包时间';
                    $arr['value'] = $res['epiboly_time'];
                    $arrs[] = $arr;
                }else{
                    if(!in_array($vv->field,['employee_user','employee_user_id'])){
                        $arr['field'] = $vv->field;
                        $arr['size'] = $vv->size;
                        $arr['field_name'] = $vv->field_name;
                        $arr['value'] = $res[$vv->field];
                        $arrs[] = $arr;
                    }
                }
            }
            $array[] = $arrs;
        }
    }
}
